//
//  __link.swift
//  eemall
//
//  Created by zhuxietong on 2018/9/1.
//  Copyright © 2018年 zhuxietong. All rights reserved.
//

import Foundation
import soapp
// import mosdks

public enum MallRouter:String{
    case 商品订单 = "order"
    case 商城公告 = "shopnotice"
    case 商品详情 = "goods"
    case 品牌主页 = "merch"
    case 商品列表 = "goodslist"
    case 团购商品 = "groupsgoods"
    case 团购首页 = "groupsIndex"
    case 物流详情 = "expresslist"
    case call = "call"
    
    public static var orderMsg:EeMsgType{
        get{
            return EeMsgType(rawValue: MallRouter.商品订单.rawValue)
        }
    }
}

public class MallLinkRaw: NSObject {
    
}

public class MallLink:MallLinkRaw,AppRouter{
    
}

public extension AppRouter where Self:MallLinkRaw{
    static func open(link: String, at: UIViewController?, present: NavPresentType?) -> Bool {
        print("__ss___SII\(link)")
        let info = AppLink.paw(link: link)

        var canopen = false
        if let mlink = MallRouter(rawValue: info.path)
        {
            var newCtr:UIViewController? = nil
            switch mlink {
            case .商品详情:
                let ctr = Goods.DetailCtrType.init()
                ctr.mo.model = info.params.mutable_dictionary
                newCtr = ctr
            case .品牌主页:
                let ctr = Goods.SellerCtrType.init()
                ctr.mo.model = info.params.mutable_dictionary
                newCtr = ctr
            case .call:
                let mobile = info.params.mutable_dictionary["mobile",""]
                if let url = NSURL(string: "tel://\(mobile)"){
                    UIApplication.shared.openURL(url as URL)
                }
            case .商品列表:
                let ctr = Goods.GoodsListCtrType.init()
                ctr.listMode = .link(params: info.params)
                ctr.mo.model = info.params.mutable_dictionary
                newCtr = ctr
//                Goods.seeGoods(filters: info.params, at: at)
            case .商品订单:
                let ctr = Goods.OrderCtrType.init()
                ctr.mo.model = info.params.mutable_dictionary
                newCtr = ctr
            
//                Goods.seeOrder(obj: info.params.mutable_dictionary, at: at)
            case .物流详情:
                let ctr = LogisticsCtr()
                ctr.mo.model = info.params.mutable_dictionary
                newCtr = ctr
            default:
                break
            }
            canopen = AppLink.show(at: at, controller: newCtr, present: present)
        }
        return canopen
    }
    
    
}


//enum MallLink:String,AppRouter {
//    static func open(link: String, at: UIViewController?, present: NavPresentType?) -> Bool {
//        return true
//    }
//
//
//
//
//
//    case 商品订单 = "order"
//    case 商城公告 = "shopnotice"
//    case 商品详情 = "goods"
//    case 商品列表 = "goodslist"
//    case 团购商品 = "groupsgoods"
//    case 团购首页 = "groups"
//
//
//
//
//}

